package net.sk.china.city.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import net.sk.china.city.controller.base.BaseController;
import net.sk.china.city.domain.dto.AjaxResult;
import net.sk.china.city.domain.ArExchangeLocation;
import net.sk.china.city.service.IArExchangeLocationService;
import net.sk.china.city.domain.dto.TableDataInfo;

/**
 * 兑换地点Controller
 * 
 * @author gxf
 * @date 2024-04-25
 */
@Api(tags = "兑换地点")
@RequiredArgsConstructor
@RestController
@RequestMapping("/supermarket/location")
public class ArExchangeLocationController extends BaseController
{
    @Autowired
    private IArExchangeLocationService arExchangeLocationService;

    /**
     * 查询兑换地点列表
     */
    @ApiOperation("兑换地点列表")
    @PreAuthorize("hasAnyAuthority('supermarket:location:list')")
    @GetMapping("/list")
    public TableDataInfo list(ArExchangeLocation arExchangeLocation)
    {
        startPage();
        List<ArExchangeLocation> list = arExchangeLocationService.selectArExchangeLocationList(arExchangeLocation);
        return getDataTable(list);
    }

    /**
     * 导出兑换地点列表
     */
    @PreAuthorize("hasAnyAuthority('supermarket:location:export')")
    @PostMapping("/export")
    public void export(HttpServletResponse response, ArExchangeLocation arExchangeLocation)
    {
        List<ArExchangeLocation> list = arExchangeLocationService.selectArExchangeLocationList(arExchangeLocation);
//        ExcelUtil<ArExchangeLocation> util = new ExcelUtil<ArExchangeLocation>(ArExchangeLocation.class);
//        util.exportExcel(response, list, "兑换地点数据");
    }

    /**
     * 获取兑换地点详细信息
     */
    @ApiOperation("兑换地点详情")
    @PreAuthorize("hasAnyAuthority('supermarket:location:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(arExchangeLocationService.selectArExchangeLocationById(id));
    }

    /**
     * 新增兑换地点
     */
    @ApiOperation("新增兑换地点")
    @PreAuthorize("hasAnyAuthority('supermarket:location:add')")
    @PostMapping
    public AjaxResult add(@RequestBody ArExchangeLocation arExchangeLocation)
    {
        return toAjax(arExchangeLocationService.insertArExchangeLocation(arExchangeLocation));
    }

    /**
     * 修改兑换地点
     */
    @ApiOperation("修改兑换地点")
    @PreAuthorize("hasAnyAuthority('supermarket:location:edit')")
    @PutMapping
    public AjaxResult edit(@RequestBody ArExchangeLocation arExchangeLocation)
    {
        return toAjax(arExchangeLocationService.updateArExchangeLocation(arExchangeLocation));
    }

    /**
     * 删除兑换地点
     */
    @ApiOperation("删除兑换地点")
    @PreAuthorize("hasAnyAuthority('supermarket:location:remove')")
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(arExchangeLocationService.deleteArExchangeLocationByIds(ids));
    }


    @ApiOperation("地点和id")
    @GetMapping("/getLocationAndId")
    public AjaxResult getNameAndId()
    {
        return success(arExchangeLocationService.getLocationAndId());
    }
}
